package com.gede.web.esael.Controller;

import com.gede.web.esael.EsaelApplication;
import com.gede.web.esael.Util.DCSUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class YozoControler {
    Logger logger= LoggerFactory.getLogger(YozoControler.class);
    @Value("${yozo.upload}")
   private  String uploadurl;
    @Value("${yozo.onlinefile}")
    private String onlinefile;

    /**
     * 将方档上传，选择文档要转换的类型对应的编码
     * 得到 {"result":0,"data":["http://192.168.8.23:8080/2020/09/25/MjAwOTI1NTAxODU3OTUy.ofd"],"message":"转换成功","type":29}
     * @param path 文件路径
     * @param convertType 转换类型代码
     * @return  {"result":0,"data":["http://192.168.8.23:8080/2020/09/25/MjAwOTI1NTAxODU3OTUy.ofd"],"message":"转换成功","type":29}
     */
    @PostMapping("/yozo/doctoofd")
    public String docToOfd(String path,String convertType){
        logger.info("我来转换方档类型来了");
     String url= this.uploadurl;
     //   System.out.println(url);
       String res= DCSUtil.SubmitPost(url,path,convertType);
        return res;
    }

    /**
     *
     * @param downloadUrl   类型转换反出来的url
     * @param convertType    类型代码
     * @return {"result":0,"data":["http://192.168.8.23:8080/dcs.web/yozo/yozo/index.html?eyJpc0Rvd25sb2FkIjowLCJzZWFyY2hTdHJpbmciOm51bGwsImZpbGUiOiIvZGNzLndlYi9wZGZ2aWV3P2ZpbGVQYXRoPTIwMjAvMDkvMjUvTWpBd09USTFOVGt6TXpVeE1EVTEiLCJ3IjpbeyJjb2xvciI6ImdyYXkiLCJhbHBoYSI6MC4yLCJyZXBlYXQiOjEsImFuZ2xlIjotNTAsImZvbnRzaXplIjo1MCwidGV4dCI6IiIsInBvc2l0aW9uIjoiY2VudGVyIiwiZm9udCI6IuWui+S9kyJ9XSwiaXNQcmludCI6MCwiaXNDb3B5IjowfQ=="],"message":"转换成功","type":21}
     */

    @PostMapping("/yozo/onlinefile")
    public String onLineFile(String downloadUrl,String convertType){
        logger.info("我要在线查看了");
        String url= this.onlinefile;
        Map<String, String> map = new HashMap<String, String>();
        map.put("downloadUrl", downloadUrl);
        map.put("convertType", convertType);
        String res = DCSUtil.sendPost(url, map);
        return res;
    }



}
